package cn.dxj1016.lesson03;

import cn.dxj1016.lesson02.utils.JdbcUtils;

import java.sql.*;

public class TestUpdate {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        try {
            connection = JdbcUtils.getConnenction();//获取数据库连接
//            区别
//            使用？代替占位符参数
            String sql = "UPDATE users SET `NAME`=?,`PASSWORD`=? WHERE id=?";
            preparedStatement = connection.prepareStatement(sql);//预编译SQL，先写SQL，然后不执行
//            手动给参数赋值

            preparedStatement.setString(1, "qinjiang");
            preparedStatement.setString(2, "5678807");
            preparedStatement.setInt(3, 5);
//            执行
            int i = preparedStatement.executeUpdate();
            if (i > 0) {
                System.out.println("修改成功");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.release(connection,preparedStatement,null);
        }
    }
}
